package com.fhnew.app.util;

import android.widget.TextView;

public class StringUtil {

    public static void format (TextView tv) {
        if (tv != null) {
            if (!tv.getText().toString().contains(".")) {
                tv.append("0.00");
            } else {
                String[] split = tv.getText().toString().split("\\.");
                switch (split.length) {
                    case 1:
                        tv.setText(split[0] + ".00");
                        break;
                    case 2:
                        tv.setText(split[0] + ".");
                        switch (split[1].length()) {
                            case 1:
                                tv.append(split[1] + "0");
                                break;
                            case 2:
                                tv.append(split[1]);
                                break;
                            default:
                                if (split[1].length() > 1)
                                    tv.append(split[1].substring(0, 2));
                                break;
                        }
                        break;
                }
            }
        }

    }
}
